package com.lytfly.flowable.modules.flow.service.impl;

import com.lytfly.flowable.modules.flow.service.BaseProcessService;
import com.lytfly.flowable.modules.flow.service.IFlowableProcessDefinitionService;
import lombok.extern.slf4j.Slf4j;
import org.flowable.common.engine.api.FlowableException;
import org.flowable.engine.RepositoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @author : bruce.liu
 * @title: : FlowableProcessDefinitionServiceImpl
 * @projectName : flowable
 * @description: 流程定义service
 * @date : 2019/11/1314:18
 */
@Service
@Slf4j
public class FlowableProcessDefinitionServiceImpl extends BaseProcessService implements IFlowableProcessDefinitionService {

    @Autowired
    RepositoryService repositoryService;


    @Override
    public void suspendOrActivateProcessDefinitionById(String processDefinitionId, int suspensionState) {
        final int activeStatus = 1;
        final int suspendStatus = 2;
        if (suspensionState == activeStatus) {
            repositoryService.suspendProcessDefinitionById(processDefinitionId, true, null);
            log.info("流程定义ID:{},已挂起成功!", processDefinitionId);
        } else if (suspensionState == suspendStatus) {
            repositoryService.activateProcessDefinitionById(processDefinitionId, true, null);
            log.info("流程定义ID:{},已激活成功!", processDefinitionId);
        } else {
            throw new FlowableException("参数异常");
        }
    }
}
